/*
Copyright (C) 2011 Ing. Marek Hubal

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "core.h"
#include "IStopWatch.h"

// .....................................................................................................................
// Konstruktor
// .....................................................................................................................
IStopWatch::IStopWatch(void) {
}
// .....................................................................................................................
// .....................................................................................................................
// Destruktor
// .....................................................................................................................
IStopWatch::~IStopWatch(void) {
}
// .....................................................................................................................
// .....................................................................................................................
// Spustenie merania
// .....................................................................................................................
void __fastcall IStopWatch::StartMeassure(void) {
	FStart = clock(); // Ulozim zaciatok merania
}
// .....................................................................................................................
// .....................................................................................................................
// Ukoncenie merania
// .....................................................................................................................
void __fastcall IStopWatch::EndMeassure(INT32 pRunCount) {
	FEnd = clock(); // Ulozim koniec merania
	FRunCount = pRunCount; // Ulozim pocet iteracii
}
// .....................................................................................................................
// .....................................................................................................................
// Pocet iteracii v merani
// .....................................................................................................................
INT32 __fastcall IStopWatch::RunCount(void) {
	return FRunCount; // Vratim pocet iteracii
}
// .....................................................................................................................
// .....................................................................................................................
// Pocet uplynutych sekund v merani
// .....................................................................................................................
DOUBLE __fastcall IStopWatch::ElapsedTime(void) {
	return (DOUBLE)((FEnd - FStart) / (DOUBLE)CLOCKS_PER_SEC);
}
// .....................................................................................................................
// .....................................................................................................................
// Vykonnost posledneho merania
// .....................................................................................................................
DOUBLE __fastcall IStopWatch::Performance(void) {
	return (DOUBLE)RunCount() / ElapsedTime();
}
// .....................................................................................................................
// .....................................................................................................................
// Vypisanie vysledkov merania
// .....................................................................................................................
void __fastcall IStopWatch::PrintResultMessage(void) {
	printf("\nResult: elapsed time: %.4lf sec, iterations: %d, performance: %.0lf iterations per sec. Execution time of one iteration: %.4lf msec.\n", (DOUBLE)ElapsedTime(), RunCount(), (DOUBLE)Performance(), (DOUBLE)((1.0 / Performance()) * 1000.0));
}
// .....................................................................................................................
